import React,{Component}  from 'react'
import moment from 'moment'
import {
		message,
		Form,
		DatePicker,
		Select,
		Button
	} from 'antd';
import { benchCodeList} from '../../utils/dataConfig';
const FormItem = Form.Item;
const Option = Select.Option;
const RangePicker = DatePicker.RangePicker;

import style from './index.less'
/**
 * 产品组合选择输入控件
 * @param {[type]} data     [列表数据]
 * @param {[type]} value    [默认值]
 * @param {[type]} dispatch [方法]
 * @param {[type]} tag      [所属model]
 */
const ProlistSelect=({data,value,dispatch,tag})=>{
	console.log('111111',data,value,tag)
	const myProps={
					value,
					data,
					onChange:(v)=> {
						if(v){
							data.map((item,i)=>{
								if(v===item.value){
									dispatch({
										type: `${tag}/setState`,
										payload: {
											lPortId:item.id
										}
									})
								}
							})
						}else{
							dispatch({
								type: `${tag}/setState`,
								payload: {
									lPortId:null
								}
							})
						}

					},
					style:{width:130},
					mode:"combobox",
					allowClear:true,
					// labelInValue:true
				}
	return (
		<Select {...myProps}>
			{
				 data&&data&&data.map((item,i)=><Option value={item.value} key={i}>{item.value}</Option>)
			}
		</Select>
	)
}
/**
 * 产品组合选择输入控件2
 * @param {[type]} data     [列表数据]
 * @param {[type]} value    [默认值]
 * @param {[type]} dispatch [方法]
 * @param {[type]} tag      [所属model]
 */

/*const PdtSelect=({data,dispatch,tag,isShow,pdtsearchId,onePdt})=>{
	console.log('PdtSelect>>>>>',data,tag,'pdtsearchId>',pdtsearchId,"onePdt>",onePdt)
	const myProps ={
		defaultValue:onePdt?onePdt:'',
		allowClear:true,
	}
	// function searchData(){
	// 	dispatch({
	//   	type:`${tag}/getListPdt`,
	//   	payload:{
	//   		name:pdtsearchId
	//   	}
	//   })
	// }
	function handleChange(value) {
		console.log('22222',value)
		if(value&&value.length <= 0 ){
			dispatch({
				type:`${tag}/setState`,
				payload:{
					lPortId:'',
				}
			})
		}else if(value == undefined){
			dispatch({
				type:`${tag}/setState`,
				payload:{
					lPortId:'',
				}
			})
		}
		if(value&&value.length >=2){
			dispatch({
		  	type:`${tag}/getListPdt`,
		  	payload:{
		  		name:value
		  	}
		  })
		}else if(value&&value.length < 2){
			dispatch({
		  	type:`${tag}/setState`,
		  	payload:{
		  		ListPdt:[]
		  	}
		  })
		}else if(value&&value.length >3){
			dispatch({
		  	type:`${tag}/setState`,
		  	payload:{
		  		ListPdt:[]
		  	}
		  })
		}
	}
	function handleSelect(v){
		console.log('222vv',v)
		const codeArr = v.split('-')[0]
		data.map((item)=>{
			if(item.value == v){
				const lPortId = item.id;
				dispatch({
					type:`${tag}/setState`,
					payload:{
						lPortId:lPortId,
					}
				})
			}
		})
	}
	return(
		<div className={style.selectDiv}>
			<Select
			{...myProps}	
				mode="combobox"
		    style={{ width: 150 }}
		    placeholder="Please select"
			 	onChange={handleChange}
			 	onSelect={handleSelect}
			>
				{
				 data?data.map((item,i)=><Option value={item.value} key={item.id}>{item.value}</Option>):null
				}
			</Select>
		</div>
		
	)
	
}
*/
/**
 * 时间区间选择输入控件
 * @param {[type]} data     [列表数据]
 * @param {[type]} value    [默认值]
 * @param {[type]} dispatch [方法]
 * @param {[type]} tag      [所属model]
 */
const TimeRangeSelect=({data,value,dispatch,tag})=>{
	console.log('TimeRangeSelect>>',data,value,tag)
	const myProps={
		defaultValue:data&&data.length?data[0].name:'',
		data,
		value,
		onSelect:(v)=> {
			dispatch({
				type: `${tag}/setState`,
				payload: {
					timeRange:v,
					beginDate:null,
					endDate:null
				}
			})
		},
		style:{width:100}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={item.value} key={i}>{item.name}</Option>)
			}
		</Select>
	)
}
/**
 * 日期选择控件
 * @param {[type]} dispatch  [方法]
 * @param {[type]} beginDate [开始时间]
 * @param {[type]} endDate   [结束时间]
 * @param {[type]} tag       [所属model]
 */
const DateRangePicker=({dispatch,beginDate,endDate,tag})=>{
	const myProps={
		onChange:(v)=> {
			if(v.length){
				dispatch({
						type: `${tag}/setState`,
						payload: {
							beginDate:v[0].format("YYYYMMDD"),
							endDate:v[1].format("YYYYMMDD")
						}
					})
			}else{
				dispatch({
						type: `${tag}/setState`,
						payload: {
							beginDate:'',
							endDate:''
						}
					})
			}

		},
		style:{width:130}
	}
	if(beginDate){
		myProps.defaultValue=[moment(beginDate), moment(endDate)]
	}

	return (
		<RangePicker
			{...myProps}
			// format="YYYY/MM/DD"
			//style={{ width: 200 }}
			style={{ width: 212 }}
			/>
	)
}

/**
 * 行业分类选择输入控件
 * @param {[type]} data     [列表数据]
 * @param {[type]} value    [默认值]
 * @param {[type]} dispatch [方法]
 * @param {[type]} tag      [所属model]
 */
const IndustrySelect=({data,value,dispatch,tag})=>{
	const myProps={
					defaultValue:data&&data.length?data[0].name:'',
					data,
					value,
					onSelect:(v)=> {
						dispatch({
								type: `${tag}/setState`,
								payload: {
									indunum:v
								}
							})
					},
					style:{width:210}
				}
	return (
		<Select {...myProps}>
			{
				 data.map((item,i)=><Option value={item.value} key={i}>{item.name}</Option>)

			}
		</Select>
	)
}
/**
 * 基准代码选择输入控件
 * @param {[type]} data     [列表数据]
 * @param {[type]} value    [默认值]
 * @param {[type]} dispatch [方法]
 * @param {[type]} tag      [所属model]
 */
const BenchCodeSelect=({data,value,dispatch,tag})=>{
	const myProps={
					value,
					data,
					onChange:(v)=> {
						if(v){
							data.map((item,i)=>{
								if(v===item.value){
									dispatch({
										type: `${tag}/setState`,
										payload: {
											cBenchCode:item.id
										}
									})
								}
							})
						}else{
							dispatch({
								type: `${tag}/setState`,
								payload: {
									cBenchCode:null
								}
							})
						}

					},
					style:{width:130},
					mode:"combobox",
					allowClear:true,
					// labelInValue:true
				}
	return (
		<Select {...myProps}>
			{
				 data&&data.map((item,i)=><Option value={item.value} key={i}>{item.value}</Option>)
			}
		</Select>
	)
}
/**
 * 基准代码选择输入控件
 * @param {[type]} data     [列表数据]
 * @param {[type]} value    [默认值]
 * @param {[type]} dispatch [方法]
 * @param {[type]} tag      [所属model]
 */
const BenchCodeSelect1=({data,value,dispatch,tag})=>{
	console.log('BenchCodeSelect1',data,value,tag)
	const myProps={
					defaultValue:'沪深300',
					data,
					value,
					onSelect:(v) =>{
						dispatch({
								type: `${tag}/setState`,
								payload: {
									cBenchCode:v
								}
							})
					},
					style:{width:80}
				}
	return (
		<Select {...myProps}>
			{
				 data&&data.map((item,i)=><Option value={item.id} key={i}>{item.value}</Option>)
			}
		</Select>
	)
}
/*const BenchCodeSelect2=({data,dispatch,tag,BisShow,BpdtsearchId,pdtsearchId})=>{
	console.log('BenchCodeSelect2>>>>>',data,BisShow,tag)

		// function searchData(){
		// 	dispatch({
		//   	type:`prolist/getListPdt`,
		//   	payload:{
		//   		name:BpdtsearchId
		//   	}
		//   })
		// }
	
	
	function handleChange(value) {
		if(BisShow=='brinson'&&value&&value.length <= 0 ){
			dispatch({
				type:`brinson/setState`,
				payload:{
					cBenchCode:'',
				}
			})
		}else if(BisShow=='brinson'&&value == undefined){
			dispatch({
				type:`brinson/setState`,
				payload:{
					cBenchCode:'',
				}
			})
		}else if(BisShow==undefined&&value&&value.length <= 0 ){
			dispatch({
				type:`overview/setState`,
				payload:{
					cBenchCode:'',
				}
			})
		}else if(BisShow==undefined&&value == undefined){
			dispatch({
				type:`overview/setState`,
				payload:{
					cBenchCode:'',
				}
			})
		}
		if(value&&value.length >=2){
			if(BisShow==undefined){
				dispatch({
			  	type:`overview/getListPdt`,
			  	payload:{
			  		name:value
			  	}
			  })
			}else{
				dispatch({
			  	type:`${tag}/getListPdt`,
			  	payload:{
			  		name:value
			  	}
			  })
			}
			
		}else if(value&&value.length <2){
			dispatch({
		  	type:`${tag}/setState`,
		  	payload:{
		  		BListPdt:[]
		  	}
		  })
		}else if(value&&value.length >3){
			dispatch({
		  	type:`${tag}/setState`,
		  	payload:{
		  		BListPdt:[]
		  	}
		  })
		}
		
	}
	function handleSelect(v){
		data.map((item)=>{
			console.log('PdtSelect>L',v,item)
			if(item.value == v){
				const lPortId = item.id;
				if(tag=='prolist' && BisShow=='brinson' ){
					dispatch({
						type:`brinson/setState`,
						payload:{
							cBenchCode:lPortId,
						}
					})
				}else{
					dispatch({
						type:`overview/setState`,
						payload:{
							cBenchCode:lPortId,
						}
					})
				}
				
			}
		})
	}
	return(
		<div className={style.selectDiv}>
			<Select
				allowClear={true}
				mode="combobox"
		    style={{ width: 150 }}
		    placeholder="Please select"
			 	onChange={handleChange}
			 	onSelect={handleSelect}
			 	// defaultValue={BenchCodeName?BenchCodeName:''}
			>
				{
				 data?data.map((item,i)=><Option value={item.value} key={item.id}>{item.value}</Option>):null
				}
			</Select>
		</div>
		
	)
}*/
export {
  ProlistSelect,
	TimeRangeSelect,
	DateRangePicker,
	IndustrySelect,
	BenchCodeSelect,
	BenchCodeSelect1,
	// PdtSelect,
	// BenchCodeSelect2,
}
